package com.yxpweb.redisdao.dao.impl;

import com.yxpweb.redisdao.entity.User;
import dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author : yang.xp
 * @date : 2021/11/5 11:03
 * @description :
 */
@Component
public class UserDaoImpl implements UserDao {

    @Autowired
    RedisTemplate redisTemplate;

    @Autowired
    MongoTemplate mongoTemplate;

    public void selectRedisKey() {
        redisTemplate.opsForValue().set("test", "test");
    }

    public void findMongoKey() {
        User user = new User();
        user.setId(10098l);
        user.setUserName("yxp");
        user.setPassWord("xxx");
        mongoTemplate.save(user);

        Query query = new Query(Criteria.where("_id").is(10098l));
        List<User> users = mongoTemplate.find(query, User.class);
        users.stream().forEach(System.out::println);
    }
}
